package com.example.demo.domain.application;

import com.example.demo.domain.application.factory.ApplicationAbstractFactory;
import lombok.Getter;

/**
 * 应用规模
 * @author yingjianhua
 */
@Getter
public enum ApplicationScale {

    /**
     * 系统应用
     */
    SYSTEM("system", SystemApplication.SystemApplicationFactory.class),
    /**
     * 企业应用
     */
    COMPANY("company", CompanyApplication.CompanyApplicationFactory.class),
    /**
     * 个人应用
     */
    PERSON("person", PersonApplication.PersonApplicationFactory.class),
    ;
    /**
     * 应用规模的名字
     */
    private final String code;
    /**
     * 该规模的应用的工厂实现类
     */
    private final Class<? extends ApplicationAbstractFactory> factoryClass;

    ApplicationScale(String code, Class<? extends ApplicationAbstractFactory> factoryClass) {
        this.code = code;
        this.factoryClass = factoryClass;
    }

    public static ApplicationScale ofCode(String code) {
        for (ApplicationScale value : ApplicationScale.values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        throw new RuntimeException("暂时还不支持该类型的应用");
    }
}
